package org.geeks.gsspringsecurity.base.domain;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.PostUpdate;
import javax.persistence.PrePersist;

import org.hibernate.annotations.UpdateTimestamp;
import org.springframework.data.annotation.CreatedDate;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

/**
 * Domain基类
 * 
 * @author Geek-S
 *
 */
@MappedSuperclass
@Getter
@Setter
@ToString
public class BaseDomain implements Serializable {

	private static final long serialVersionUID = 1L;

	/**
	 * 主键
	 */
	@Id
	@GeneratedValue
	private Long id;

	/**
	 * 创建时间
	 */
	@CreatedDate
	private Date createTime;

	/**
	 * 更新时间
	 */
	@UpdateTimestamp
	private Date updateTime;

	@PrePersist
	private void setCreateDate() {
		Date date = new Date();
		createTime = date;
		updateTime = date;
	}

	@PostUpdate
	private void setUpdateDate() {
		Date date = new Date();
		updateTime = date;
	}
}